package cs342.uwosh.group1.mycontacts.Threads;

import java.util.ArrayList;
import java.util.List;

import com.mycontacts.R;
import com.mycontacts.R.id;
import com.mycontacts.R.layout;

import cs342.uwosh.group1.mycontacts.Contact;
import cs342.uwosh.group1.mycontacts.MainActivity;
import cs342.uwosh.group1.mycontacts.SqlConnect;

import android.os.AsyncTask;
import android.widget.ArrayAdapter;

public class GetContactsByCategoryTask extends AsyncTask<Integer, Object, ArrayList<Contact>>{

	@Override
	protected ArrayList<Contact> doInBackground(Integer... arg0) {
		SqlConnect db = MainActivity.db;
		return (ArrayList<Contact>)db.getContactsFromCategory(arg0[0]);
	}
	
	protected void onPostExecute(ArrayList<Contact> arg0)
	{	
		ArrayList<Contact> contacts = arg0;

        MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item, R.id.contactItem, contacts);

        MainActivity.listOfContacts.setAdapter(MainActivity.contactListAdapter);
		
	}
}
